package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/28.
 */
@HttpInlet(Conn.GOODS_GOODS_LIST)
public class GoodsListGet extends BaseAsyGet<GoodsListGet.GoodsListEntity> {

    public String sid, tid, title = "";

    public GoodsListGet(AsyCallBack<GoodsListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected GoodsListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            GoodsListEntity goodsListEntity = new GoodsListEntity();

            JSONArray array = object.optJSONArray("list");

            for (int i = 0; i < array.length(); i++) {

                GoodsEntity goodsEntity = new GoodsEntity();

                JSONObject entityObject = array.optJSONObject(i);

                goodsEntity.id = entityObject.optString("id");
                goodsEntity.title = entityObject.optString("title");
                goodsEntity.picurl = Conn.IMAGE_URL + entityObject.optString("picurl");
                goodsEntity.deprice = entityObject.optString("deprice");
                goodsEntity.num = entityObject.optString("num");

                goodsListEntity.goodsListEntity.add(goodsEntity);

            }

            return goodsListEntity;

        }

        return null;
    }

    public static class GoodsListEntity {

        public List<GoodsEntity> goodsListEntity = new ArrayList<>();
    }
    public static class GoodsEntity {

        public String id, title, picurl, deprice, num;

    }


}
